<?php
/**
 * Created by PhpStorm.
 * User: weijer
 * Date: 2018/10/26
 * Time: 21:17
 */

namespace common\validate;

use think\Validate;

class Tenant extends BaseValidate
{
    //验证规则
    protected $rule = [];

    // Select 验证场景定义
    public function sceneSelect()
    {
        return $this->append('param', 'array')
            ->append('param.filter', 'array')
            ->append('param.page', 'array');
    }

    // Create 验证场景定义
    public function sceneCreate()
    {
        return $this->append('data.name', 'require|max:255')
            ->append('data.status', 'in:active,invalid');
    }

    // Update 验证场景定义
    public function sceneUpdate()
    {
        return $this->append('data.id', 'require')
            ->append('data.name', 'max:255')
            ->append('data.status', 'in:active,invalid')
            ->append('data.role', 'in:from_tenant,to_tenant');
    }

    // Delete 验证场景定义
    public function sceneDelete()
    {
        return $this->append('param.filter', 'require|array')
            ->append('param.filter.id', 'require|array');
    }

    // SwitchStatus 验证场景定义
    public function sceneSwitchStatus()
    {
        return $this->append('param.filter', 'require');
    }

    // GetDepartmentTree 验证场景定义
    public function sceneGetDepartmentTree()
    {
        return $this->append('param.filter.id', 'require');
    }

    // JoinDepartment 验证场景定义
    public function sceneJoinDepartment()
    {
        return $this->append('data.user_id', 'require')
            ->append('data.tenant_id', 'require')
            ->append('data.department_id', 'require')
            ->append('data.role_id', 'require')
            ->append('data.status', 'in:active,invalid');
    }

    // SelectDepartmentUser 验证场景定义
    public function sceneSelectDepartmentUser()
    {
        return $this->append('param.filter.tenant_id', 'integer')
            ->append('param.filter.department_id', 'integer')
            ->append('param.filter.name_or_phone', 'array')
            ->append('param.page', 'array');
    }

    // DeleteDepartmentUser 验证场景定义
    public function sceneDeleteDepartmentUser()
    {
        return $this->append('param.filter', 'require');
    }

    // SaveRole 验证场景定义
    public function sceneSaveRole()
    {
        return $this->append('param.filter', 'require')
            ->append('data.role_id', 'require');
    }

    // SaveDept 验证场景定义
    public function sceneSaveDept()
    {
        return $this->append('param.filter', 'require')
            ->append('data.department_id', 'require');
    }

    // SelectTenantUser 验证场景定义
    public function sceneSelectTenantUser()
    {
        return $this->append("param", "array")
            ->append("param.filter", "array");
    }

    // SwitchToTenant 验证场景定义
    public function sceneSwitchToTenant()
    {
        return $this->append("param.filter.tenant_id", "require|integer");
    }

    // ApplyAppendToTenant 验证场景定义
    public function sceneApplyAppendToTenant()
    {
        return $this->append("data.tenant_id", "require|integer")
            ->append("data.reasons", "require|max:512");
    }

    // AgreeAppendUserToTenant 验证场景定义
    public function sceneAgreeAppendUserToTenant()
    {
        return $this->append("data.tenant_apply_id", "require|integer")
//            ->append("data.department_id", "require|integer")
//            ->append("data.role_id", "require|integer")
            ->append("data.status", "require|in:active,invalid");
    }

    // RefuseAppendUserToTenant 验证场景定义
    public function sceneRefuseAppendUserToTenant()
    {
        return $this->append("data.tenant_apply_id", "require|integer");
    }

    // GetTenantApplyUserList 验证场景定义
    public function sceneGetTenantApplyUserList()
    {
        return $this->append("param.filter.tenant_id", "require|integer");
    }

    // GetTenantDetail 验证场景定义
    public function sceneGetTenantDetail()
    {
        $this->append('param.filter.tenant_id', 'require|integer');
    }

    // SaveUserDepartment 验证场景定义
    public function sceneSaveUserDepartment()
    {
        return $this->append('param.filter.user_id', 'require')
            ->append('param.filter.tenant_id', 'require')
            ->append('data', 'require|array');
    }

    // SaveUserDepartmentItem 验证场景定义
    public function sceneSaveUserDepartmentItem()
    {
        return $this->append('department_id', 'require|integer')
            ->append('role_id', 'require|integer');
    }

    // GetUserDepartmentStepIdList 验证场景定义
    public function sceneGetUserDepartmentStepIdList()
    {
        return $this->append('param.user_id', 'integer')
            ->append('param.tenant_id', 'integer')
            ->append('param.role_id_list', 'array');
    }

    // SetUserPosition 验证场景定义
    public function sceneSetUserPosition()
    {
        return $this->append('data.user_id_list', 'require|array');
    }

    // CheckDepartmentUserExist 验证场景定义
    public function sceneCheckDepartmentUserExist()
    {
        return $this->append('param.filter', 'require|array');
    }

    // GetWorkOrderRelatedTenant 验证场景定义
    public function sceneGetWorkOrderRelatedTenant()
    {
        return $this->append('param.filter.belong_type', 'require')
            ->append('param.filter.current_tenant_type', 'require')
            ->append('param.filter.project_tenant_id', 'require')
            ->append('param.filter.belong_project_tenant_id', 'require');
    }

    // RegisterTenant 注册团队
    public function sceneRegisterTenant()
    {
        return $this->append('data', 'require')
            ->append("data.company_name", "require|min:3|max:255")
            ->append('data.media_front_of_id', 'require|array')
            ->append("data.media_reverse_of_id", "require|array")
            ->append('data.sms_code', 'alphaNum|length:6')
            ->append('data.phone', 'require|regex:mobile')
            ->append('data.name', 'require|max:128')
            ->append("data.id_number", "require|regex:idCard");
    }

    // Disband 解散团队
    public function sceneDisband()
    {
        return $this->append('data', 'require')
            ->append('data.tenant_id', 'require|integer')
            ->append('data.sms_code', 'require|alphaNum|length:6');
    }

    // UpdateInfo 更新团队信息
    public function sceneUpdateInfo()
    {
        return $this->append('data', 'require')
            ->append('data.id', 'require|integer')
            ->append('data.media_front_of_id', 'require|array')
            ->append("data.media_reverse_of_id", "require|array")
            ->append('data.sms_code', 'alphaNum|length:6')
            ->append('data.phone', 'require|regex:mobile')
            ->append('data.name', 'require|max:128')
            ->append("data.id_number", "require|regex:idCard")
            ->append('data.service_category', 'require|array');
    }
}
